# !/bin/sh

import argparse
import os
from controller.discSpaceManager import DiscSpaceManager
from controller.songManager import SongManager
import sys
	
def main():
	parser = argparse.ArgumentParser(description='Ordered copy of music folders to SD/USB.')
	parser.add_argument('sources', metavar='src', nargs='+', help='Source folders or files.')
	parser.add_argument('target', metavar='tgt', help='Target folder')
	parser.add_argument('--id3', action="store_true", help='Save the folder in the order described in ID3 song number')
	args = parser.parse_args()
	real_tgt = os.path.realpath(args.target)

	ds_manager = DiscSpaceManager()
	acum_size = 0.0
	print "\n"
	for src in args.sources:
		real_src = os.path.realpath(src)
		src_size = ds_manager.calculate_folder_size(real_src)
		print "{0} size {1:.2f} MB".format(real_src, src_size/ 1024)
		acum_size += src_size
	print "\nTotal size to move {0:.2f} MB".format(acum_size / 1024)
	
	print "\nAvailable size to move {0:.2f} MB".format(ds_manager.calculate_available_size(real_tgt) / 1024)

	song_manager = SongManager()
	for src in args.sources:
		real_src = os.path.realpath(src)

		if args.id3:
			song_manager.walk_dir_id3(real_src, real_tgt)
		else:
			song_manager.walk_dir(real_src, real_tgt)

if __name__ == "__main__":
	sys.exit(main())
